package cn.jingyuan.swan.system.web.controller.gateway;

import cn.jingyuan.bee.utils.bean.BeanUtils;
import cn.jingyuan.swan.cloud.core.RestResult;
import cn.jingyuan.swan.cloud.core.RestResultUtils;
import cn.jingyuan.swan.system.domain.gateway.entity.GatewayAccessLog;
import cn.jingyuan.swan.system.service.GatewayAccessLogService;
import cn.jingyuan.swan.system.web.restful.GatewayAccessLogRestful;
import cn.jingyuan.swan.system.web.restful.model.GatewayAccessLogRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 网关日志接口
 */
@Api(tags = "网关日志接口")
@Slf4j
@RestController
public class GatewayAccessLogController implements GatewayAccessLogRestful {

    @Resource
    GatewayAccessLogService accessLogService;

    @ApiOperation(value = "记录网关访问日志", notes = "记录网关访问日志")
    @Override
    public RestResult<Long> log(GatewayAccessLogRequest reqDto) {
        GatewayAccessLog accessLog = new GatewayAccessLog();
        BeanUtils.copyProperties(reqDto, accessLog);
        Long id = accessLogService.save(accessLog);

        return RestResultUtils.ok(id);
    }

}
